﻿using System.Windows;
using System.Windows.Forms;
using PSE.Deployment.SetupBase;
using PSE.Deployment.SetupBase.UI;
using System.IO;
using PSE.Deployment.ConfigurationManager.Controls;

namespace PSE.Deployment.SetupBase.UI
{
    public partial class InstalationSource : BaseWindow
    {
        public InstalationSource()
        {
            this.InitializeComponent();

            this.txtPath.Text = SetupMainFactory.GetInstance().Parameter.InstalationSource;
        }

        private void ShowFileDialog()
        {
            FolderBrowserDialog fbd = new FolderBrowserDialog();
            fbd.Description = "Escolha o caminho que os arquivos de instalação do Sistema";
            fbd.ShowNewFolderButton = true;
            fbd.SelectedPath = txtPath.Text;

            if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                txtPath.Text = fbd.SelectedPath + "\\";
            }

            fbd.Dispose();
        }

        private void BtnOk_Click(object sender, RoutedEventArgs e)
        {
            if (!Util.Windows.CheckInstallationSource(this.txtPath.Text))
            {
                ConfigurationMessageBox.Show("O caminho de instalação do Sistema informado é inválido. Por favor informe um caminho válido.", "Erro", ConfigurationMessageBoxButton.Ok, ConfigurationMessageBoxImage.Error);
                return;
            }

            SetupMainFactory.GetInstance().Parameter.InstalationSource = this.txtPath.Text;

            this.DialogResult = true;

            this.Close();
        }

        private void BtnCancel_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;

            this.Close();
        }

        private void btnSelectPath_Click(object sender, RoutedEventArgs e)
        {
            ShowFileDialog();
        }
    }
}
